<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 订单管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="css/public.css" rel="stylesheet" type="text/css">
	<link href="css/index.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/orderService.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/DatePicker/WdatePicker.js" defer="defer"></script>
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>

<div class="wrap100">

	<!--full begin-->
    <div class="full">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>订单快速搜索</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>               
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
            <form action="<%=basePath%>trade/orderList" method="GET">
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>合同号：                </td>
                <td><input type="text" name="productNo" value="${searchCond.orderCode}" size="25" class="input" /></td>
                <td>下单时间查询：</td>
                <td><input type="text" name="startDate" id="startDate" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="input"/></td>
                <td>结束时间：</td>
                <td><input type="text" name="endDate" id="endDate" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"  class="input"/></td>                
              </tr>
            </table>
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
              	<td>客人公司：</td>
                <td><input type="text" name="productNo" value="${searchCond.company}" size="25" class="input" /></td>
                <td>国家：</td>
                	<td>
                	<select id="country">
                	<option value="">-- 国家 --</option>
					<c:forEach var="country" items="${countryList}">
					<option value="${country.codeName}">${country.codeName}</option>
					</c:forEach>
				    </select> 
                </td>
                <c:if test="${sessionScope.memberSessionInfo.userType.value eq '0'}">
                <td>业务员：</td>
                <td>
	                <select id="user">
	                <option value="">-- 业务员 --</option>
					<c:forEach var="user" items="${userList}">					
					<option value="${user.id}">${user.userName}</option>
					</c:forEach>
					</select>
	            </td>
	            </c:if>
                <td><input type="submit" style="background:url(images/search.gif);width:92px;height:25px;border:0;margin:0;" value="" /></td>
              </tr>
            </table>
	</div>
            <!--产品详细信息 end-->
          
 
    		<!--寄样管理 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>订单管理</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightPropertyList1">
            	<div class="title1">
                <table width="3647"  border="0" cellpadding="1" cellspacing="1" bgcolor="#dfe5e9">
                  <tr>
                    <th colspan="16"  align="center">&nbsp;</th>
                    <th colspan="6" >与客户款项</th>
                    <th colspan="6" >与工厂款项</th>
                    <th colspan="2" >商检</th>
                    <th colspan="2" >报关</th>
                    <th colspan="3" >&nbsp;</th>
                    <th colspan="4" >工厂增值税票</th>
                    <th colspan="2" >退税资料</th>
                    <th colspan="2" >&nbsp;</th>
                  </tr>
                  <tr>
                    <th width="1%" align="left"><input type="checkbox" name="allSelectId" id="allSelectId" onclick="judgmentChecjBox('allSelectId','id')" /></th>
                    <th width="3%" align="left">合同号</th>
                    <th width="2%" align="left">订单状态</th>
                    <th width="2%" align="left">收到客户<br />预付款时间</th>
                    <th width="2%" align="left">国家</th>
                    <th width="3%" align="left">客人公司</th>
                    <th width="3%" align="left">客人名字</th>
                    <th width="1%" align="left">客户等级</th>
                    <th width="2%" align="left">合同总金额<br /> USD</th>
                    <th width="3%" align="left">收款帐户</th>
                    <th width="2%" align="left">成交方式</th>
                    <th width="3%" align="left">下单工厂</th>
                    <th width="2%" align="left">金额</th>
                    <th width="2%" align="left">下单时间</th>
                    <th width="3%" align="left">预计交货时间</th>
                    <th width="2%" align="left">出货港口</th>
                    <th width="2%" align="left">第一次货款</th>
                    <th width="3%" align="left">时间</th>
                    <th width="2%" align="left">第二次货款</th>
                    <th width="2%" align="left">时间</th>
                    <th width="2%" align="left">第三次货款</th>
                    <th width="2%" align="left">时间</th>
                    <th width="2%" align="left">第一次货款</th>
                    <th width="2%" align="left">时间</th>
                    <th width="2%" align="left">第二次货款</th>
                    <th width="3%" align="left">时间</th>
                    <th width="2%" align="left">第三次货款</th>
                    <th width="3%" align="left">时间</th>
                    <th width="2%" align="left">是否需要<br /> 商检</th>
                    <th width="3%" align="left">做商检时间</th>
                    <th width="3%" align="left">报关资料<br />    是否做好</th>
                    <th width="3%" align="left">报关资料<br />                寄出时间</th>
                    <th width="2%" align="left">订舱时间</th>
                    <th width="3%" align="left">报关时间</th>
                    <th width="2%" align="left">开船时间</th>
                    <th width="2%" align="left">是否需要<br />                    开票</th>
                    <th width="3%" align="left">开票资料是否<br />                    做好并给工厂</th>
                    <th width="2%" align="left">工厂是否<br />                    寄回发票</th>
                    <th width="2%" align="left">收到工厂<br />                    发票时间</th>
                    <th width="2%" align="left">退税资料<br />                    是否退回</th>
                    <th width="2%" align="left">退税资料<br />                    收到时间</th>
                    <th width="3%" align="left">整套退税单据<br />                    提交给财务时间</th>
                    <th width="3%" align="left">备注</th>                  </tr>
                </table>
</div>
            	<div class="list1">
            	  <table width="3647"  border="0" cellpadding="1" cellspacing="1" bgcolor="#dfe5e9">
            	  	<c:forEach var="order" items="${orderList}">
            	    <tr>
            	      <td width="1%" align="left"><input type="checkbox" value="${order.id}" name="id"/></td>
            	      <td width="3%" align="left">${order.orderCode}</td>
            	      <td width="2%" align="left">${order.status.codeName}</td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.advandesDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.cuntry.codeName}</td>
            	      <td width="3%" align="left">${order.customerCompany}</td>
            	      <td width="3%" align="left">${order.customerName}</td>
            	      <td width="1%" align="left">${order.grade.codeName}</td>
            	      <td width="2%" align="left">${order.contractAmount}</td>
            	      <td width="3%" align="left">${order.account}</td>
            	      <td width="2%" align="left">${order.soldfor.codeName}</th>
            	      <td width="3%" align="left">${order.factory}</td>
            	      <td width="2%" align="left">${order.amount}</td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.orderDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.deliveryTime}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.shipment}</td>
            	      <td width="2%" align="left">${order.customerReceipt1}</td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.customerReceiptDate1}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.customerReceipt2}</td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.customerReceiptDate2}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.customerReceipt3}</td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.customerReceiptDate3}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.factoryReceipt1}</td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.factoryReceiptDate1}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.factoryReceipt2}</td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.factoryReceiptDate2}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.factoryReceipt3}</td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.factoryReceiptDate3}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.inspection}</td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.inspectionDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="3%" align="left">${order.customsData}</td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.customsDataDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.bookingDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.customsDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.sailDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.kaipiao}</td>
            	      <td width="3%" align="left">${order.kaipiaoToFactory}</td>
            	      <td width="2%" align="left">${order.factorySendInvoice}</td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.receiveFactoryDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="2%" align="left">${order.efundInformation}</td>
            	      <td width="2%" align="left"><fmt:formatDate value="${order.efundInformationDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="3%" align="left"><fmt:formatDate value="${order.efundInfoFinanceDate}" pattern="yyyy-MM-dd"/></td>
            	      <td width="3%" align="left">${order.detail}</td>
          	      </tr>
            	  </c:forEach>
				  <c:if test="${empty orderList}"><tr><td colspan="43" style="text-align:center">没有相关记录！</td></tr></c:if>
           	      </table>
          	  </div>
				<div class="list"></div>
            </div>
            <!--寄样管理 end-->


            <!--统计 end-->
            <div class="total">
                <div class="fl Statistics">总数：<strong>${searchStat.totalCount}</strong> 条
                <script type="text/javascript">
				var pageControl = new wpagebar('pageControl');
				pageControl.argName = "pageIndex";
				pageControl.pageCount = ${searchStat.pageCount};
				pageControl.load();
				</script>
				</div>
                <div class="fr Operating">                
                    <ul>
                        <!-- <li><input name="复 制" type="button" class="button" value="复 制" /></li> -->
                        <li><input name="添 加" type="button" class="button" value="添 加" onclick="addOrder()"/></li>
                        <li><input name="修 改" type="button" class="button" value="修 改" onclick="editOrders()"/></li>
                        <c:if test="${sessionScope.memberSessionInfo.userType.value eq '0'}">
                        <li><input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/></li>
                        </c:if>
                        <li><input name="导出EXCEL" type="button" class="button" value="导出EXCEL" onclick="exportExcel()"/></li>
                    </ul>
                </div>
            </div>
 
            <!--统计 end-->
            
    </div>
	<!--full end-->
    <div id="win_temp" style="display:none">
	<div id="winCon_1">
	<table class="tabView" style="margin-top:5px">
		<tr><th width="100">订单号：</th><td><input type="text" name="orderCode0" id="orderCode0" value=""/>
			<input type="hidden" name="orderId0" id="orderId0" /></td></tr>
		<tr><th>业务员：</th><td>
			<select id="user0">
			<c:forEach var="user" items="${userList}"><option value="${user.id}">${user.userName}</option></c:forEach>
			</select></td>			
		</tr>
		<tr><th>国家：</th><td><input type="text" name="country0" id="country0"/></td></tr>		
		<tr><th>客户：</th><td><input type="text" name="customer0" id="customer0" value=""/></td></tr>
		<tr><th>金额：</th><td><input type="text" name="money0" id="money0" value=""/></td></tr>
		<tr><th>成交日期：</th><td>
			<input type="text" name="closingDate0" id="closingDate0" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
			</td></tr>
		<tr><th>出货日期：</th><td>
			<input type="text" name="shipmentDate0" id="shipmentDate0" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
			</td></tr>
		<tr><td colspan="2" style="text-align:center;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitOrder()"/></td></tr>
	</table>
	</div>
</div>  
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>
<script  type="text/javascript">
function exportExcel(){			
	var ids = getSelectedCheckBoxValues('id');
	if(ids == "")
		alert("请先选择要导出的信息！");
	else {
		window.open("<%=basePath%>trade/exportExcel?t=5&ids="+ids);
	}
}
function addOrder(){
	location='trade/orderEdit?action=add';
	//WIN.show('<font size=5>添加订单信息</font>',$('winCon_1'),{height:300});
}
function editOrders(){
	var objs = document.getElementsByName("id");	
	var ids=0;
	var vas='';
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids++;
			vas=objs[i].value;			
		}
	}
	if(ids!=1){
		alert("请选择一条且只能选择一条信息进行编辑！");
		return ;
	}	
	if(vas==''){
		alert("请先选择要操作的信息");
		return ;
	}else{
		location='trade/orderEdit?action=modify&id='+vas;
	}	
}
function editOrder(id){
	WIN.show('<font size=5>修改订单信息</font>',$('winCon_1'),{height:300});
	orderService.getOrderById(id,function(data){
		$('orderId0').value=data.id;
		$('orderCode0').value=data.orderCode;
		$('user0').value=data.user.id;
		$('country0').value=data.country;
		$('customer0').value=data.customer;
		$('money0').value=data.money;
		$('closingDate0').value=formatDate(data.closingDate);
		$('shipmentDate0').value=formatDate(data.shipmentDate);		
	})
}
function delOrder(id){
	if(confirm("删除订单信息，确定删除 ？")){
		WIN.showpg();
		orderService.delOrderById(id,{
			callback:function(f){WIN.closepg();alert("删除成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("删除失败，请重试");},
			errorHander:function(err){}
		})
	}
}
function delsellMultiple(){			
	var objs = document.getElementsByName("id");
	var ids='';	
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids+=objs[i].value+",";
		}
	}
	if(ids==''){
		alert("请先选择要操作的信息");
		return ;
	}
	ids = ids.substring(0,ids.length - 1);
	
	if(confirm("您确定要删除?")){
		if(ids == ""){
			alert("请先选择要删除的信息！");
			return false;
		}else{
			orderService.deleteOrderByIds(ids,{
				callback:function(f){alert("删除成功");reload();},
				exceptionHandler:function(message){alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
}
function submitOrder(){
	var data={
			id:			$('orderId0').value,
			orderCode:	$('orderCode0').value,
			user:		{id:$('user0').value},
			country:	$('country0').value.trim(),
			customer:	$('customer0').value,
			money:      $('money0').value,
			closingDate:  $('closingDate0').value.trim()?new Date($('closingDate0').value.trim().replace(/-/g,"/")):'',
			shipmentDate:  $('shipmentDate0').value.trim()?new Date($('shipmentDate0').value.trim().replace(/-/g,"/")):''
	}
	
	if(''==data.orderCode){alert('订单号不能为空');return;}
	if(''==data.user.id){alert('请选择业务员');return;}
	
	if(''==data.id){
		submitOrder.data=data;		
		orderService.existsOrderCode(data.orderCode,{
			callback:function(f){if(f){alert('此订单号已经存在，请更改');}else{submit(submitOrder.data);}},
			exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");reload();},
			errorHander:function(err){}
		})
	}else{
		submit(data);
	}
}
function submit(data){
	WIN.close();
	WIN.showpg();
	orderService.editOrder(data,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}

</script>
</body>
</html>
